import axios from 'axios'

axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
axios.defaults.baseURL = '/xiamen'

export function post (url, params) {
  return new Promise((resolve, reject) => {
    axios.post(url, params)
      .then(response => {
        resolve(response.data)
      }).catch(error => {
        reject(error)
      })
  })
}
export function get (url, params = {}) {
  return new Promise((resolve, reject) => {
    axios.get(url, {
      params: params
    }).then(response => {
      resolve(response.data)
    }).catch(error => {
      reject(error)
    })
  })
}

export default {
  getAllInfo (param1, param2, param3) { // 查询所有
    if (param3 === 0 || param3 === 1) {
      return get(`${param1}/select?currentPage=${param2}&pageSize=12&isShow=${param3}`)
    }
    return get(`${param1}/select?currentPage=${param2}&pageSize=12`)
  },
  getClassification (params) { // 查询分类
    return get(`${params}/classification`)
  },
  getInfoByClassification (param1, param2) { // 根据分类查询
    return get(`${param1}/select?currentPage=1&pageSize=12&cateId=${param2}`)
  },
  changeStatus (param1, param2, param3) { // 修改审核状态
    return get(`${param1}/validate/${param2}/${param3}`)
  },
  changeBatchStatus (param1, param2, param3) { // 批量修改审核状态
    return get(`${param1}/validateBatch/${param2}/${param3}`)
  }
}
